<!--
<template>
  <div>
    <form @submit.prevent="handleSubmit">
      <label>用户名</label>
      <input type="text" v-model="user.name" name="name" value=""><br>
      <label>密码</label>
      <input type="password" v-model="user.password" name="password" value=""><br>
      <input type="submit" value="登录">
    </form>
  </div>
</template>

<script>
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Axios from 'axios'

Vue.use(ElementUI);

import updateRoutes from "../util/loadingRouter";

export default {
  name: "Login",
  data() {
    return {
      user: {
        name: "",
        password: ""
      }
    };
  },
  methods: {
    handleSubmit() {
      Axios({
        method: "get",
        url:"/api/signIn",
        responseType: "stream",
      }).then(response => {
        if (response.data!=null){
          // 显示成功消息
          this.$message({
            message: '登录成功',
            type: 'success'
          });
        }
      })
      /*Axios.get("/api/getUserList").then(res => {
        if (res.data!=null){
          // 显示成功消息
          this.$message({
            message: '登录成功',
            type: 'success'
          });
        }
      })*/


      /*// 登录逻辑，例如验证用户名和密码
      console.log(this.user.name);
      console.log(this.user.password);*/



      /*// 动态添加路由逻辑（如果需要）
      updateRoutes();*/

      // 使用 Vue Router 进行页面跳转
      /*this.$router.push({ path: '/list', query: { age: 12 }});*/
    }
  }
};
</script>

<style scoped>

</style>
-->


<template>
  <div>
    <el-form ref="loginForm" :model="user" label-width="80px">
      <el-form-item label="账号">
        <el-input v-model="user.id"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="user.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Axios from 'axios';

Vue.use(ElementUI);

import updateRoutes from '../util/loadingRouter';

export default {
  name: 'Login',
  data() {
    return {
      user: {
        id: '',
        password: ''
      }
    };
  },
  methods: {
    handleSubmit() {
      Axios.post('/api/signIn', this.user)
        .then(response => {
          console.log(response)
          if (response.status === 200) {
            // 显示成功消息
            this.$message({
              message: '登录成功',
              type: 'success'
            });

            // 动态添加路由逻辑（如果需要）
            updateRoutes(); // 传递Vue Router实例

            // 使用 Vue Router 进行页面跳转
            this.$router.push({ path: '/list', query: { age: 12 }});
          } else {
            this.$message.error('登录失败');
          }
        })
        .catch(error => {
          console.error('登录请求失败:', error);
          this.$message.error('登录失败，请检查您的网络或服务器状态');
        });
    }
  }
};
</script>

<style scoped>
/* 根据需要添加样式 */
</style>
